#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int d[N],v[N],a[N],tj[N];
int p[N];
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m,l,v0;
		cin>>n>>m>>l>>v0;
		for(int i=1;i<=n;i++)
		{
			cin>>d[i]>>v[i]>>a[i];
		}
		for(int i=1;i<=m;i++)
		{
			cin>>p[i];
		}
		sort(p+1,p+m+1);
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if((a[i]<=0 && v[i]<=v0)||d[i]>p[m])	continue;
			if(a[i]>=0 && v[i]>v0)
			{
				ans++;
				continue;
			}
		}
		cout<<ans<<' ';
		if(ans==0)	cout<<m<<endl;
		else
		{
			cout<<m-1<<endl;
		}
	}
	return 0;
}
